﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2017._01._24TestWork2
{
    class DefineVectors
    {
        int[] array;
        private int index;
        
        public int[] Vector(int size)
        {
            array = new int[size];
            Random rnd = new Random();
            for (int i = 0; i < size; i++)
            {
                array[i] = rnd.Next();
            }
            index = size;
            return array;
        }

        public int this[int index]
        {
            set
            {
                if (array[index] >= array.Length || array[index] < 0)
                    new IndexOutOfRangeException();
                else array[index] = value;
            }
            get
            {
                return array[index];
            }
        }

        public int[] SumArrays(int[] array1, int[] array2)
        {
            int[] sumArray = new int[array1.Length];
            if (array1.Length == array2.Length)
            {
                for (int i = 0; i < sumArray.Length; i++)
                {
                    sumArray[i] = array1[i] + array2[i];
                }
            }
            else Console.WriteLine("Массивы разной длины");
            return sumArray;

        }

        public int[] SubstractionArrays(int[] array1, int[] array2)
        {
            int[] substractionArray = new int[array1.Length];
            if (array1.Length == array2.Length)
            {
                for (int i = 0; i < substractionArray.Length; i++)
                {
                    substractionArray[i] = array1[i] - array2[i];
                }
            }
            else Console.WriteLine("Массивы разной длины");
            return substractionArray;
        }

        //public int GetElementByIndex(int NumOfElement)
        //{
        //    int element = 0;
        //    if (NumOfElement >= Index || NumOfElement < 0)
        //    { throw new IndexOutOfRangeException(); }
        //    else
        //        element = array[NumOfElement];
        //    return element;
        //}

        public void PrintArray()
        {
            for (int i = 0; i < array.Length; i++)
            {
                Console.WriteLine(array[i]);
            }
        }

    }
}
